//
//  DCGisticsView.m
//  Driver
//
//  Created by 大橙子 on 2018/11/7.
//  Copyright © 2018 Tomous. All rights reserved.
//

#import "DCGisticsView.h"
#import "DCGisticsCell.h"
@interface DCGisticsView ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,strong) DCImageAndTextLabel *imageLabel;
@property (nonatomic,strong) UILabel *stateLabel;

@property (nonatomic,strong) UITableView *myTableView;
@property(strong,nonatomic) NSArray* dataArray;

@end
@implementation DCGisticsView
-(instancetype)initWithSourceData:(NSArray *)dataArray state:(NSString *)state
{
    if (self = [super init]) {
        _dataArray = dataArray;
        _imageLabel = [[DCImageAndTextLabel alloc]init];
//        _imageLabel.backgroundColor = [UIColor redColor];
        _imageLabel.imageView.image = IMAGENAME(@"task_detail_genzong");
        _imageLabel.textLabel.text = @"   节点跟踪";
        [self addSubview:_imageLabel];
        
        _stateLabel = [[UILabel alloc]init];
        _stateLabel.textColor = [UIColor redColor];
        _stateLabel.textAlignment = NSTextAlignmentCenter;
        _stateLabel.font = FONT(17);
        _stateLabel.text = state;
        [self addSubview:_stateLabel];
        
        _myTableView = [[UITableView alloc]init];
        _myTableView.scrollEnabled = NO;
        _myTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _myTableView.dataSource = self;
        _myTableView.delegate = self;
        [self addSubview:_myTableView];
        
    }
    return self;
}
-(void)layoutSubviews
{
    [super layoutSubviews];
    _imageLabel.frame = CGRectMake(10, 0, ScreenWidth/2, 40);
    _stateLabel.frame = CGRectMake(_imageLabel.right+10, 0, ScreenWidth/2, _imageLabel.height);
    _myTableView.frame = CGRectMake(10, 40, self.width-20, self.height-40);
}
#pragma mark--UITableView
-(NSInteger) numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
-(NSInteger) tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section{
    return _dataArray.count;
}
-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    DCGisticsCell *cell = [DCGisticsCell cellWithTableView:tableView];
    if (indexPath.row < [self.dataArray count]) {
        for (DCGisticsModel *model in self.dataArray) {
            if (indexPath.row == self.dataArray.count - 1) {
                model.isBottomShow = NO;
            }else {
                model.isBottomShow = YES;
            }
        }
        cell.model = self.dataArray[indexPath.row];
    }
//    DCGisticsModel *model = self.dataArray[indexPath.row];
//    cell.model = model;
    return cell;
    
}
-(CGFloat)tableView:(UITableView*)tableView heightForRowAtIndexPath:(NSIndexPath*)indexPath
{
    return 40;
}


/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
